package top.yekongle.shop.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @author Hank Lau
 * @date 2022/5/3
 */
public class ObjectMapperUtil {
	private static ObjectMapper objectMapper = new ObjectMapper();

	public static String objectToString(Object object)  {
		try {
			return objectMapper.writeValueAsString(object);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static <T> T stringToObject(String json,Class<T> object) {
		try {
			return objectMapper.readValue(json,object);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return null;
	}
}
